package cn.tedu;

import java.sql.*;

public class Demo03 {
    public static void main(String[] args) throws SQLException {
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false","root","root");
        Statement s = conn.createStatement();
        //定义语句  DDL
        /*s.execute("create table jdbct1");*/
        //增删改   DML
       /* int a = s.executeUpdate("insert into emp(name) values('tom')");
        s.executeUpdate("update emp set name='jerry' where name='tom'");
        s.executeUpdate("delete from emp where name='jerry'");*/
        //查找语句  DQL
        ResultSet rs = s.executeQuery("select sal,name from emp");
        //遍历结果集合的数据
        while(rs.next()){
            /*String name = rs.getString("name");
            double sal = rs.getDouble("sal");*/
            //通过select后面的位置查询数据
            String name = rs.getString(2);
            double sal = rs.getDouble(1);
            System.out.println(name+":"+sal);
        }
        System.out.println("执行完毕!");
        conn.close();
    }
}
